package com.ws.game.lesson3.fire
{
	import com.ws.game.common.framework.BaseCtrl;
	import com.ws.game.common.utils.MoveDirectionType;
	import com.ws.log.WSLog;
	
	import flash.display.Sprite;
	import flash.geom.Matrix;
	
	public class FaceObject extends ActionObject
	{
		protected var _face:Sprite;
		protected var _hp:uint = 100;
		public function get hp():uint
		{
			return _hp;
		}
		
		public function hurt(val:uint):void
		{
			_hp -= val;
			if (_hp <= 0){
				this.dispose();
			}		
		}
		
		public function FaceObject(aCtrl:BaseCtrl,face:Sprite)
		{
			super(aCtrl);
			this._face = face;
			this.addChild(_face);
		}
		
		override public function set direction(value:uint):void{
			super.direction = value;
			if(_face){
				var angle:Number;
				var tx:Number;
				var ty:Number;			
				switch(super.direction)
				{
					case MoveDirectionType.UP:
						angle = 0;
						tx = 0;
						ty = 0;
						break;
					case MoveDirectionType.RIGHT:
						angle = Math.PI * 0.5;
						tx = _face.width;
						ty = 0;
						break;
					case MoveDirectionType.DOWN:
						angle = Math.PI;
						tx = _face.width;
						ty = _face.height;
						break;
					case MoveDirectionType.LEFT:
						angle = Math.PI * 1.5;
						tx = 0;
						ty = _face.height;
						break;
				}
				
				_face.transform.matrix = new Matrix(Math.cos(angle), Math.sin(angle),Math.sin(angle)*-1,Math.cos(angle),tx,ty);
			}
		}
		
		override public function dispose():void{
			if(_face)
			{
				_face.graphics.clear();
				this.removeChild(_face);
				_face = null;
			}
			super.dispose();
		}
	}
}